<template>
  <div class="app-container">
    <el-card>
      <el-table v-loading="loading" :data="workingSupplierList" @row-dblclick="getTeamType" border>
        <el-table-column label="供应商ID" align="center" prop="supplierId" />
<!--        <el-table-column label="供应商名称" align="center" prop="supplierName" />-->
        <el-table-column label="店铺名称" align="center" prop="shopsName" />
<!--        <el-table-column label="供应商类型" align="center" prop="supplierType">-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{scope.row.supplierType == 1 ? '自营' : '平台'}}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="店铺类型" align="center" prop="supplierTypeform">
          <template slot-scope="scope">
            <el-tag>{{scope.row.supplierTypeform == 1 ? '店铺' : '施工队'}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="供应商联系人" align="center" prop="linkMan" />
        <el-table-column label="联系电话" align="center" prop="phoneNumber" />
<!--        <el-table-column label="供应商开户银行名称" align="center" prop="bankName" :show-overflow-tooltip="true" />-->
<!--        <el-table-column label="银行账号" align="center" prop="bankAccount" :show-overflow-tooltip="true"/>-->
        <el-table-column label="供应商地址" align="center" prop="address" :show-overflow-tooltip="true" />
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.supplierStatus == 1">禁用</el-tag>
            <el-tag type="success" v-else-if="scope.row.supplierStatus == 0">启用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="最后修改时间" align="center" prop="modifiedTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifiedTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="250px" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleAddPic(scope.row)"
              v-hasPermi="['qualification:info:addpic']"
            >新增荣誉资质</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleListPic(scope.row)"
            >查看荣誉资质</el-button>

            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >特色服务</el-button>

          </template>
        </el-table-column>

      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </el-card>


    <el-card>
<div align="center">
  <h2>资质荣誉</h2>
</div>
      <el-form :model="queryParamspic" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">

        <el-form-item label="图片是否有效" prop="conStatus">
          <el-select v-model="queryParamspic.conStatus" placeholder="请选择图片是否有效" clearable size="small">
            <el-option label="无效" value="0" />
            <el-option label="有效" value="1" />
          </el-select>
        </el-form-item>

        <el-form-item label="证书类型" prop="qualifiType">
          <el-select v-model="queryParamspic.qualifiType" @change="getList" id="teamType" placeholder="请选择证书类型" clearable size="small">
            <el-option label="营业执照" value="1" />
            <el-option label="施工资质" value="2" />
            <el-option label="荣誉证书" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>


      <el-table v-loading="loading" :data="infopicList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!--<el-table-column label="资格证书图片ID" align="center" prop="qualifiPicId" />-->
        <!--<el-table-column label="施工队ID" align="center" prop="constructionId" />-->
        <el-table-column label="图片URL" align="center" prop="conUrl" />
        <el-table-column label="图片是否有效" align="center" prop="conStatus" >
          <template slot-scope="scope">
            {{scope.row.conStatus == 0 ? '无效' : '有效'}}
          </template>
        </el-table-column>
        <el-table-column label="最后修改时间" align="center" prop="modifiedTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifiedTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="证书类型" align="center" prop="qualifiType" >
          <template slot-scope="scope">
            {{scope.row.qualifiType == 1 ? '营业执照' : scope.row.qualifiType == 2 ? '施工资质' : '荣誉证书'}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdatePic(scope.row)"
              v-hasPermi="['qualification:info:editpic']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeletePic(scope.row)"
              v-hasPermi="['qualification:info:removepic']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalpic>0"
        :total="totalpic"
        :page.sync="queryParamspic.pageNum"
        :limit.sync="queryParamspic.pageSize"
        @pagination="getListpic"
      />

      <!-- 添加或修改施工队图片信息对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="160px">
          <el-form-item label="证书类型" prop="qualifiType">
            <el-select v-model="form.qualifiType" @change="getList" id="teamType" placeholder="请选择证书类型">
              <el-option label="营业执照" value="1" />
              <el-option label="施工资质" value="2" />
              <el-option label="荣誉证书" value="3" />
            </el-select>
          </el-form-item>

          <el-form-item label="资质荣誉图片" prop="conUrl">
            <el-upload
              :multiple="multiple"
              action="${pageContext.request.contextPath}/lookup/editEvidence/123"
              list-type="picture-card"
              :auto-upload="false"
              :http-request="uploadFile"
              ref="upload"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <!--<el-button @click="subPicForm" style="text-align: center;margin-top: 20px" type="primary">提交上传</el-button>-->

          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

    </el-card>


    <el-dialog :title="titlefw" :visible.sync="openfw" width="500px" append-to-body>
      <el-form ref="formfw" :model="formfw" :rules="rules" label-width="80px">

        <el-form-item label="特色服务">
<!--          <editor v-model="formfw.tese" :min-height="192"/>-->
          <QuillEditor v-model="formfw.tese" @getChildrenStatus="getChildrenStatus"></QuillEditor>
        </el-form-item>
        <el-form-item label="施工擅长">
          <editor v-model="formfw.shanchang" :min-height="192"/>
<!--          <QuillEditoryi v-model="formfw.shanchang" @getChildrenStatus="getChildrenStatusa"></QuillEditoryi>-->
        </el-form-item>
        <el-form-item label="服务区域">
          <editor v-model="formfw.fuwu" :min-height="192"/>
<!--          <QuillEditorer v-model="formfw.fuwu" @getChildrenStatus="getChildrenStatusi"></QuillEditorer>-->

        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormfw">确 定</el-button>
        <el-button @click="cancelfw">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import Editor from '@/components/Editor';
  import QuillEditor from '@/components/Quill-editor';
  import QuillEditoryi from '@/components/Quill-editor';
  import QuillEditorer from '@/components/Quill-editor';
  import { fwgetInfo,fwupdateInfo } from "../../../api/supper";
  import {
    listWorkingSupplier,
  } from "@/api/construction/workingSupplier";
  import {addUplouad}  from "@/api/uploadimg";
  import { qualificalistInfo,qualificagetInfo,qualificaaddInfo,qualificaupdateInfo,qualificadelInfo,qualificaexportInfo,uploadImage } from "@/api/construction/qualificationpic";
  export default {
    name: "index",
    components: { Editor,QuillEditor,QuillEditoryi,QuillEditorer },
    data() {
      return {
        infopicList:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        title: "",
        titlefw: "",
        // 总条数
        total: 0,
        totalpic: 0,
        // 分类表格数据
        workingSupplierList: null,
        // 是否显示弹出层
        open: false,
        openfw: false,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 查询参数
        queryParamspic:{
          pageNum: 1,
          pageSize: 10,
          supplierIdnum:'',
        },
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        defaultProps: {
          children: "children",
          label: "label",
        },

        // 表单参数
        form: {
          numsupplierId:'',
        },
        formfw:{

        },
        // 表单校验
        rules: {
          // conUrl: [
          //   { required: true, message: "图片URL不能为空", trigger: "blur" }
          // ],
          conStatus: [
            { required: true, message: "图片是否有效：0无效 1有效不能为空", trigger: "blur" }
          ],
          qualifiType: [
            { required: true, message: "证书类型不能为空", trigger: "change" }
          ]
        },
        //上传图片
        fileUrl:null,
        dialogVisible:false,
        dialogImageUrl:"",

      };
    },
    created() {
      this.getList();
      // this.getListpic();
    },
    methods: {
      getChildrenStatus: function(data){ // 实时更新子组件的变化
        this.formfw.tese = data
      },
      getChildrenStatusa: function(data){ // 实时更新子组件的变化
        this.formfw.shanchang = data
      },

      getChildrenStatusi: function(data){ // 实时更新子组件的变化
        this.formfw.fuwu = data
      },



// 取消按钮
      cancelfw() {
        this.openfw = false;
        this.reset();
      },
      submitFormfw(){
        // this.$refs["form"].validate(valid => {
        //   if (valid) {

              fwupdateInfo(this.formfw).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.openfw = false;
                  this.getList();
                }
              });

          // }
        // });
      },

      handleUpdate(row) {
        this.reset();
        const supplierId = row.supplierId || this.ids
        fwgetInfo(supplierId).then(response => {
          this.formfw = response.data;
          this.openfw = true;
          this.titlefw = "修改供应商信息";
        });
      },


      //上传图片
      uploadFile(file){
        this.formDate.append('file', file.file);
      },
      //添加校园图片
      subPicForm() {

      },
      handleListPic(row){
        this.queryParamspic.supplierIdnum = row.supplierId;
        console.log("***this.queryParamspic.supplierIdnum**"+this.queryParamspic.supplierIdnum)
        this.getListpic();
      },

      getListpic(){
        this.loading = true;
        qualificalistInfo(this.queryParamspic).then(res=>{
          console.log(res)
          this.infopicList = res.rows;

        this.totalpic = res.total;
        this.loading = false;
      })
      },


      handleAddPic(row){
        this.reset();
        this.dialogVisible = false;
        this.dialogImageUrl = "";
        this.open = true;
        this.title = "添加荣誉资质图片信息";
        this.form.numsupplierId = row.supplierId;
        console.log(this.form)
      },

      handleUpdatePic(row){
        this.dialogVisible = false;
        this.dialogImageUrl = "";
        this.reset();
        const qualifiPicId = row.qualifiPicId || this.ids
        qualificagetInfo(qualifiPicId).then(response => {
          this.form = response.data;
        this.open = true;
        this.title = "修改荣誉资质图片信息";
      });
      },

      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.qualifiPicId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.qualifiPicId != null) {
              qualificaupdateInfo(this.form).then(response => {
                if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getListpic();
              }
            });
            } else {
              this.formDate = new FormData()
              this.$refs.upload.submit();
              this.formDate.append('WS_CODE', "12133");
              this.formDate.append('id', this.form.numsupplierId);
              this.formDate.append('type', this.form.qualifiType);
              qualificaaddInfo(this.formDate).then(response => {
                if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.queryParamspic.supplierIdnum = row.supplierId;
                console.log("***this.queryParamspic.supplierIdnum**"+this.queryParamspic.supplierIdnum)
                this.getListpic();
                this.getList();
              }
            });

              // addUplouad(this.formDate).then(res => {
              //   this.msgSuccess("添加成功");
              //   this.open = false;
              //   this.queryParamspic.supplierIdnum = row.supplierId;
              //   console.log("***this.queryParamspic.supplierIdnum**"+this.queryParamspic.supplierIdnum)
              //   this.getListpic();
              //   this.getList();
              //
              // })

            }
          }
        });
      },

      handleDeletePic(row){
        const qualifiPicIds = row.qualifiPicId || this.ids;
        this.$confirm('是否确认删除施工队图片信息编号为"' + qualifiPicIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return qualificadelInfo(qualifiPicIds);
        }).then(() => {
          this.getListpic();
        this.msgSuccess("删除成功");
      }).catch(function() {});
      },

// 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          qualifiPicId: null,
          constructionId: null,
          conUrl: null,
          conStatus: 0,
          modifiedTime: null,
          qualifiType: null
        };
        this.resetForm("form");
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParamspic.pageNum = 1;
        this.getListpic();
      },


      /* 查询类别列表 **/
      getList(){
        this.loading = true;
        listWorkingSupplier(this.queryParams).then(response => {
          this.workingSupplierList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTeamType(row){
        this.$router.push({path:"/workingSupplier/team",query:{supplierId:row.supplierId}});
      },
    }
  }
</script>

<style scoped>

</style>
